<?php 
ini_set("include_path", ".:../:./includes:../includes");

require_once ("includes/constants.php");
require_once ("includes/common.php");
require_once ("includes/template.php");

$view = false;
$update = false;
$add = false;
if (isset ($_REQUEST['operation'])) {
	if ($_REQUEST['operation'] == "view") {
		$view = true;
		head("View Delivery Service Details");
	} else
		if ($_REQUEST['operation'] == "update") {
			$update = true;
			head("Update Delivery Service Details");
		} else
			if ($_REQUEST['operation'] == "add") {
				$add = true;
				head("Add New Delivery Service");
			}
}
?>

<table cellspacing="25px">
<tr>
<td valign="top">
<table cellspacing="5px">
	<tr>
		<td align="right">
			<label for="ds_service_name">Service Name</label>	
		</td>
		<td>
			<input   maxlength="50" id="ds_service_name" name="ds_service_name" type="text" 
			value="<?php if ($update || $view) echo $_SESSION[SHIPPING][$_REQUEST['selectedShippingOption']]['ds_service_name']; ?>"
			<?php if ($update || $view) echo 'readonly'; ?>  />	
		</td>
	</tr>
	<tr>
		<td align="right">
			<label for="ds_guaranteed">Guaranteed</label>			
		</td>
		<td>
			<select id="ds_guaranteed" name="ds_guaranteed" <?php if ($view) echo 'readonly'; ?> >
				<option value="" selected="selected" <?php if ($view) echo "disabled='disabled'" ?> >Select</option>
				<option value="YES" 
					<?php if (($update || $view) && strcasecmp($_SESSION[SHIPPING][$_REQUEST['selectedShippingOption']]['ds_guaranteed'], "YES") == 0) echo "selected='selected'" ?>   
					<?php if ($view) echo "disabled='disabled'" ?>
				> &nbsp;Yes &nbsp;
				</option>
				<option value="NO" 
					<?php if (($update || $view)  && strcasecmp($_SESSION[SHIPPING][$_REQUEST['selectedShippingOption']]['ds_guaranteed'], "NO") == 0) echo "selected='selected'" ?>   
					<?php if ($view) echo "disabled='disabled'" ?>   
				> &nbsp;No &nbsp;
				</option>
			</select>		
		</td>
	</tr>
	<tr>
		<td align="right">
			<label for="ds_delivery_time">Delivery Time</label>			
		</td>
		<td>
			<input size="2" id="ds_delivery_time" name="ds_delivery_time" maxlength="2" type="text" 
			value="<?php if ($update || $view) echo $_SESSION[SHIPPING][$_REQUEST['selectedShippingOption']]['ds_delivery_time']; ?>" 
			<?php if ($view) echo 'readonly'; ?> />			
		</td>
	</tr>
	<tr>
		<td align="right">
			<label for="ds_max_width">Max. Width</label>		
		</td>
		<td>
			<input id="ds_max_width" name="ds_max_width" maxlength="4" type="text" 
			value="<?php if ($update || $view) echo $_SESSION[SHIPPING][$_REQUEST['selectedShippingOption']]['ds_max_width']; ?>"
			<?php if ( $view) echo 'readonly'; ?> />						
		</td>
	</tr>
	<tr>
		<td align="right">
			<label for="ds_max_height">Max. Height</label>		
		</td>
		<td>
			<input id="ds_max_height" name="ds_max_height" maxlength="4" type="text" 
			value="<?php if ($update || $view) echo $_SESSION[SHIPPING][$_REQUEST['selectedShippingOption']]['ds_max_height']; ?>"
			<?php if ( $view) echo 'readonly'; ?> />						
		</td>
	</tr>
	<tr>
		<td align="right">
			<label for="ds_max_length">Max. Length</label>		
		</td>
		<td>
			<input id="ds_max_length" name="ds_max_length" maxlength="4" type="text" 
			value="<?php if ($update || $view) echo $_SESSION[SHIPPING][$_REQUEST['selectedShippingOption']]['ds_max_length']; ?>"
			<?php if ( $view) echo 'readonly'; ?> />						
		</td>
	</tr>	
	<tr>
		<td align="right">
			<label for="ds_status">Status</label>			
		</td>
		<td>
			<select id="ds_status" name="ds_status" <?php if ($view) echo 'readonly'; ?> >
				<option value="" selected="selected" <?php if ($view) echo "disabled='disabled'" ?> >Select</option>
				<option value="Active" 
					<?php if (($update || $view) && strcasecmp($_SESSION[SHIPPING][$_REQUEST['selectedShippingOption']]['ds_status'], "Active") == 0) echo "selected='selected'" ?>   
					<?php if ($view) echo "disabled='disabled'" ?>
				> &nbsp;Active &nbsp;
				</option>
				<option value="Disabled" 
					<?php if (($update || $view)  && strcasecmp($_SESSION[SHIPPING][$_REQUEST['selectedShippingOption']]['ds_status'], "Disabled") == 0) echo "selected='selected'" ?>   
					<?php if ($view) echo "disabled='disabled'" ?>   
				> &nbsp;Disabled &nbsp;
				</option>
			</select>		
		</td>
	</tr>	
</table>
</td>
<td valign="top">
<table cellspacing="5px" >	
	<tr>
		<td colspan="3">
			&nbsp;
		</td>
	</tr>
	<tr>
		<td align="center">
			<label>Weight Limit</label> 
		</td>
		<td align="center">
			<label>Price</label>
		</td>		
        <td rowspan="11" valign="top">
        	<?php if (!$view) { ?>
            <table>
                <tr>
                    <td>
                        <div class="roundButton" onclick="javascript:hideWeightPricePair();">
                            &#8593;
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="roundButton" onclick="javascript:showWeightPricePair();">
                            &#8595;
                        </div>
                    </td>
                </tr>
            </table>
			<?php } ?>
        </td>		
	</tr>
	<?php 
		if ($update || $view) {
			$count = count($_SESSION[SHIPPING][$_REQUEST['selectedShippingOption']]['price']); 
		}
		else {
			$count = 0;
		}
	?>
	<input type="hidden" name="shippingOptionPriceCount" id="shippingOptionPriceCount" value=<?php echo $count; ?> />
	<?php
	$counter = 0;
	if ($update || $view) {
	 	foreach ($_SESSION[SHIPPING][$_REQUEST['selectedShippingOption']]['price'] as $dc_weight_limit =>$dc_price) {
	 		
	?>
	 
	<tr id="weigthPricePair<?php echo $counter;?>">
		<td align="center">
			<input id="dc_weight_limit_<?php echo $counter; ?>" name="dc_weight_limit_<?php echo $counter; ?>" maxlength="5" type="text" 
			value="<?php if ($update || $view) echo $dc_weight_limit; ?>" maxlength="5" size="5"
			<?php if ( $view) echo 'readonly'; ?> />						
		</td>		
		<td align="center">
			<input id="dc_price_<?php echo $counter; ?>" name="dc_price_<?php echo $counter; ?>" maxlength="5" type="text" 
			value="<?php if ($update || $view) echo $dc_price; ?>" maxlength="5" size="5"
			<?php if ( $view) echo 'readonly'; ?> />
		</td>
	</tr>	
	 
	<?php 	
		$counter++;
		}
	}
	else { ?>
		<tr id="weigthPricePair0">
			<td  align="center">
				<input id="dc_weight_limit_0" name="dc_weight_limit_0" maxlength="5" size="5" type="text" value=""  />					
			</td>		
			<td  align="center">
				<input id="dc_price_0" name="dc_price_0" maxlength="5" size="5" type="text" value="" />
			</td>
		</tr>		
	<?php 
		$count = 1; //always display at least 1 row	
	} ?>
		
	<?php for($i = $count; $i < 10; $i++) { ?>
	<tr id="weigthPricePair<?php echo $i;?>" style="display:none">
		<td  align="center">
			<input id="dc_weight_limit_<?php echo $i; ?>" name="dc_weight_limit_<?php echo $i; ?>" maxlength="5" size="5" type="text" value=""  />					
		</td>		
		<td  align="center">
			<input id="dc_price_<?php echo $i; ?>" name="dc_price_<?php echo $i; ?>" maxlength="5" size="5" type="text" value="" />
		</td>
	</tr>
	<?php } ?>
</table>
</td>
</tr>
</table>

<?php 
	if ($add) foot("ADD", "addShippingOptionLogic.php"); 
	else if ($update) foot("UPDATE", "updateShippingOptionLogic.php?selectedShippingOption=" .
	 $_SESSION[SHIPPING][$_REQUEST['selectedShippingOption']]['ds_service_id']); 
	else foot();
?>


